<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha256-Z1K5uhUaJXA7Ll0XrZ/0JhX4lAtZFpT6jkKrEDT0drU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.14.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":-1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本篇博客本着面向接口编程的思想，整理了Java集合类的接口设计UML图，然后根据官方文档摘取了笔者觉得比较重要的API，这对增强Java集合类的整体认识无疑是很有帮助的。不过，这样一篇整理+搬运的博客也仅仅是对笔者自己有帮助罢了。 接口设计UML图 迭代模式的实现Java类库实现的 迭代器模式。 迭代器：Iterator   Modifier and Type Method and Descrip">
<meta property="og:type" content="article">
<meta property="og:title" content="Java集合类接口设计">
<meta property="og:url" content="http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/index.html">
<meta property="og:site_name" content="JsyBlog">
<meta property="og:description" content="本篇博客本着面向接口编程的思想，整理了Java集合类的接口设计UML图，然后根据官方文档摘取了笔者觉得比较重要的API，这对增强Java集合类的整体认识无疑是很有帮助的。不过，这样一篇整理+搬运的博客也仅仅是对笔者自己有帮助罢了。 接口设计UML图 迭代模式的实现Java类库实现的 迭代器模式。 迭代器：Iterator   Modifier and Type Method and Descrip">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/Collection.png">
<meta property="article:published_time" content="2021-07-22T16:00:00.000Z">
<meta property="article:modified_time" content="2021-11-05T05:51:30.927Z">
<meta property="article:author" content="SongyangJi">
<meta property="article:tag" content="数据结构">
<meta property="article:tag" content="Java集合类">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/Collection.png">


<link rel="canonical" href="http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/","path":"2021/07/23/Java集合类接口设计/","title":"Java集合类接口设计"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Java集合类接口设计 | JsyBlog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">JsyBlog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1UML%E5%9B%BE"><span class="nav-number">1.</span> <span class="nav-text">接口设计UML图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%BF%AD%E4%BB%A3%E6%A8%A1%E5%BC%8F%E7%9A%84%E5%AE%9E%E7%8E%B0"><span class="nav-number">2.</span> <span class="nav-text">迭代模式的实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BF%AD%E4%BB%A3%E5%99%A8%EF%BC%9AIterator"><span class="nav-number">2.1.</span> <span class="nav-text">迭代器：Iterator</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%AF%E8%BF%AD%E4%BB%A3%E5%AF%B9%E8%B1%A1%EF%BC%9AIterable"><span class="nav-number">2.2.</span> <span class="nav-text">可迭代对象：Iterable</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E5%85%83%E9%9B%86%E5%90%88"><span class="nav-number">3.</span> <span class="nav-text">一元集合</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BA%BF%E6%80%A7%E9%9B%86%E5%90%88"><span class="nav-number">3.1.</span> <span class="nav-text">线性集合</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#List"><span class="nav-number">3.1.1.</span> <span class="nav-text">List</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Queue"><span class="nav-number">3.1.2.</span> <span class="nav-text">Queue</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Deque"><span class="nav-number">3.1.3.</span> <span class="nav-text">Deque</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%94%AF%E4%B8%80%E6%80%A7%E9%9B%86%E5%90%88"><span class="nav-number">3.2.</span> <span class="nav-text">唯一性集合</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Set"><span class="nav-number">3.2.1.</span> <span class="nav-text">Set</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SortedSet"><span class="nav-number">3.2.2.</span> <span class="nav-text">SortedSet</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#NavigableSet"><span class="nav-number">3.2.3.</span> <span class="nav-text">NavigableSet</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E5%85%83%E9%9B%86%E5%90%88%EF%BC%88%E6%98%A0%E5%B0%84%EF%BC%89"><span class="nav-number">4.</span> <span class="nav-text">二元集合（映射）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Map"><span class="nav-number">4.1.</span> <span class="nav-text">Map</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Map-Entry"><span class="nav-number">4.2.</span> <span class="nav-text">Map.Entry</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">SongyangJi</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">251</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">45</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">109</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="SongyangJi">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="JsyBlog">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Java集合类接口设计 | JsyBlog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Java集合类接口设计
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-07-23 00:00:00" itemprop="dateCreated datePublished" datetime="2021-07-23T00:00:00+08:00">2021-07-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2021-11-05 13:51:30" itemprop="dateModified" datetime="2021-11-05T13:51:30+08:00">2021-11-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java%E9%9B%86%E5%90%88%E7%B1%BB/" itemprop="url" rel="index"><span itemprop="name">Java集合类</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p>本篇博客本着<strong>面向接口编程</strong>的思想，整理了Java集合类的接口设计UML图，<br>然后根据官方文档摘取了笔者觉得比较重要的API，这对增强Java集合类的整体认识无疑是很有帮助的。<br>不过，这样一篇整理+搬运的博客也仅仅是对笔者自己有帮助罢了。</p>
<h1 id="接口设计UML图"><a href="#接口设计UML图" class="headerlink" title="接口设计UML图"></a>接口设计UML图</h1><p><img src="/2021/07/23/Java%E9%9B%86%E5%90%88%E7%B1%BB%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1/Collection.png" alt="集合框架中的接口"></p>
<h1 id="迭代模式的实现"><a href="#迭代模式的实现" class="headerlink" title="迭代模式的实现"></a>迭代模式的实现</h1><p>Java类库实现的 <strong>迭代器模式</strong>。</p>
<h2 id="迭代器：Iterator"><a href="#迭代器：Iterator" class="headerlink" title="迭代器：Iterator"></a>迭代器：<code>Iterator</code></h2><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>hasNext()</code>如果迭代具有更多元素，则返回 <code>true</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>next()</code>返回迭代中的下一个元素。</td>
</tr>
<tr>
<td align="left"><code>default void</code></td>
<td align="left"><code>remove()</code>从底层集合中删除此迭代器返回的最后一个元素（可选操作）。</td>
</tr>
</tbody></table>
<h2 id="可迭代对象：Iterable"><a href="#可迭代对象：Iterable" class="headerlink" title="可迭代对象：Iterable"></a>可迭代对象：<code>Iterable</code></h2><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>default void</code></td>
<td align="left"><code>forEach(Consumer&lt;? super T&gt; action)</code>对 <code>Iterable</code>的每个元素执行给定的操作，直到所有元素都被处理或动作引发异常。</td>
</tr>
<tr>
<td align="left"><code>Iterator&lt;T&gt;</code></td>
<td align="left"><code>iterator()</code>返回类型为 <code>T</code>元素的迭代器。</td>
</tr>
</tbody></table>
<h1 id="一元集合"><a href="#一元集合" class="headerlink" title="一元集合"></a>一元集合</h1><p> <code>Collection</code></p>
<table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>add(E e)</code>确保此集合包含指定的元素（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>addAll(Collection&lt;? extends E&gt; c)</code>将指定集合中的所有元素添加到此集合（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>void</code></td>
<td align="left"><code>clear()</code>从此集合中删除所有元素（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>contains(Object o)</code>如果此集合包含指定的元素，则返回 <code>true</code> 。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>containsAll(Collection&lt;?&gt; c)</code>如果此集合包含指定 <code>集合</code>中的所有元素，则返回true。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>isEmpty()</code>如果此集合不包含元素，则返回 <code>true</code> 。</td>
</tr>
<tr>
<td align="left"><code>Iterator&lt;E&gt;</code></td>
<td align="left"><code>iterator()</code>返回此集合中的元素的迭代器。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>remove(Object o)</code>从该集合中删除指定元素的单个实例（如果存在）（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>removeAll(Collection&lt;?&gt; c)</code>删除指定集合中包含的所有此集合的元素（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>int</code></td>
<td align="left"><code>size()</code>返回此集合中的元素数。</td>
</tr>
<tr>
<td align="left"><code>Object[]</code></td>
<td align="left"><code>toArray()</code>返回一个包含此集合中所有元素的数组。</td>
</tr>
<tr>
<td align="left"><code>&lt;T&gt; T[]</code></td>
<td align="left"><code>toArray(T[] a)</code>返回包含此集合中所有元素的数组; 返回的数组的运行时类型是指定数组的运行时类型。</td>
</tr>
</tbody></table>
<h2 id="线性集合"><a href="#线性集合" class="headerlink" title="线性集合"></a>线性集合</h2><h3 id="List"><a href="#List" class="headerlink" title="List"></a><code>List</code></h3><p>拓展了Collection接口，所以只列出多出的方法。</p>
<table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>void</code></td>
<td align="left"><code>add(int index, E element)</code>将指定的元素插入此列表中的指定位置（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>get(int index)</code>返回此列表中指定位置的元素。</td>
</tr>
<tr>
<td align="left"><code>int</code></td>
<td align="left"><code>indexOf(Object o)</code>返回此列表中指定元素的第一次出现的索引，如果此列表不包含元素，则返回-1。</td>
</tr>
<tr>
<td align="left"><code>int</code></td>
<td align="left"><code>lastIndexOf(Object o)</code>返回此列表中指定元素的最后一次出现的索引，如果此列表不包含元素，则返回-1。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>remove(int index)</code>删除该列表中指定位置的元素（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>set(int index, E element)</code>用指定的元素（可选操作）替换此列表中指定位置的元素。</td>
</tr>
<tr>
<td align="left"><code>default void</code></td>
<td align="left"><code>sort(Comparator&lt;? super E&gt; c)</code>使用随附的 <code>Comparator</code>排序此列表来比较元素。</td>
</tr>
<tr>
<td align="left"><code>List&lt;E&gt;</code></td>
<td align="left"><code>subList(int fromIndex, int toIndex)</code>返回此列表中指定的 <code>fromIndex</code> （含）和 <code>toIndex</code>之间的视图。</td>
</tr>
</tbody></table>
<h3 id="Queue"><a href="#Queue" class="headerlink" title="Queue"></a><code>Queue</code></h3><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>add(E e)</code>将指定的元素插入到此队列中，如果可以立即执行此操作，而不会违反容量限制， <code>true</code>在成功后返回 <code>IllegalStateException</code>如果当前没有可用空间，则抛出IllegalStateException。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>offer(E e)</code>如果在不违反容量限制的情况下立即执行，则将指定的元素插入到此队列中。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>remove()</code>检索并删除此队列的头。如果队列对空，抛出异常NoSuchElementException。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>poll()</code>检索并删除此队列的头，如果此队列为空，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>element()</code>检索但不删除这个队列的头。如果队列为空，抛出异常NoSuchElementException。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>peek()</code>检索但不删除此队列的头，如果此队列为空，则返回 <code>null</code> 。</td>
</tr>
</tbody></table>
<p>要注意这三对方法的差别。</p>
<h3 id="Deque"><a href="#Deque" class="headerlink" title="Deque"></a><code>Deque</code></h3><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>void</code></td>
<td align="left"><code>addFirst(E e)</code>插入此双端队列的前面，如果它是立即可行且不会违反容量限制，抛出一个指定的元素 <code>IllegalStateException</code>如果当前没有空间可用。</td>
</tr>
<tr>
<td align="left"><code>void</code></td>
<td align="left"><code>addLast(E e)</code>在插入如果它是立即可行且不会违反容量限制，抛出此双端队列的末尾指定元素 <code>IllegalStateException</code>如果当前没有空间可用。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>offerFirst(E e)</code>在此deque的前面插入指定的元素，除非它会违反容量限制。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>offerLast(E e)</code>在此deque的末尾插入指定的元素，除非它会违反容量限制。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>getFirst()</code>检索，但不删除，这个deque的第一个元素。如果为空，抛出抛出异常NoSuchElementException。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>getLast()</code>检索，但不删除，这个deque的最后一个元素。如果为空，抛出抛出异常NoSuchElementException。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>peekFirst()</code>检索，但不删除，此deque的第一个元素，或返回 <code>null</code>如果这个deque是空的。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>peekLast()</code>检索但不删除此deque的最后一个元素，如果此deque为空，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>removeFirst()</code>检索并删除此deque的第一个元素。如果为空，抛出抛出异常NoSuchElementException</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>removeLast()</code>检索并删除此deque的最后一个元素。如果为空，抛出抛出异常NoSuchElementException</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>pollFirst()</code>检索并删除此deque的第一个元素，如果此deque为空，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>pollLast()</code>检索并删除此deque的最后一个元素，如果此deque为空，则返回 <code>null</code> 。</td>
</tr>
</tbody></table>
<p>和Queue的方法几乎一致，主要是双端队列在两端都可以进出。<br>所以，在各方法后面加上了 First、Last修饰（事实上，还有缺省First、Last的方法，但是考虑到会引起歧义，所以干脆不用）。</p>
<p><code>Deque</code>接口实际上既可以作为Queue，也可以作为Stack来使用。</p>
<p>push、pop是针对栈而言的。</p>
<p>offer、poll是针对队列而言的。</p>
<p>其中 jdk的设计是，push、pop实际上都是对队列的第一个元素的操作。</p>
<p>offer向队尾加入元素，poll从队首移除元素。</p>
<h2 id="唯一性集合"><a href="#唯一性集合" class="headerlink" title="唯一性集合"></a>唯一性集合</h2><h3 id="Set"><a href="#Set" class="headerlink" title="Set"></a><code>Set</code></h3><p>Set接口与之相同（仅仅是接口定义约束的不同），略去。</p>
<h3 id="SortedSet"><a href="#SortedSet" class="headerlink" title="SortedSet"></a><code>SortedSet</code></h3><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>E</code></td>
<td align="left"><code>first()</code>返回此集合中当前的第一个（最低）元素。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>last()</code>返回此集合中当前的最后（最高）元素。</td>
</tr>
<tr>
<td align="left"><code>SortedSet&lt;E&gt;</code></td>
<td align="left"><code>headSet(E toElement)</code>返回该集合的部分的视图，其元素严格小于 <code>toElement</code> 。</td>
</tr>
<tr>
<td align="left"><code>SortedSet&lt;E&gt;</code></td>
<td align="left"><code>tailSet(E fromElement)</code>返回此组件的元素大于或等于 <code>fromElement</code>的部分的视图。</td>
</tr>
<tr>
<td align="left"><code>SortedSet&lt;E&gt;</code></td>
<td align="left"><code>subSet(E fromElement, E toElement)</code>返回该集合的部分的视图，其元素的范围为 <code>fromElement</code> （含），为 <code>toElement</code> ，独占。</td>
</tr>
</tbody></table>
<h3 id="NavigableSet"><a href="#NavigableSet" class="headerlink" title="NavigableSet"></a><code>NavigableSet</code></h3><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>E</code></td>
<td align="left"><code>ceiling(E e)</code>返回此集合中最小元素大于或等于给定元素，如果没有此元素则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>floor(E e)</code>返回该集合中最大的元素小于或等于给定元素，如果没有这样的元素，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>higher(E e)</code>返回这个集合中的最小元素严格大于给定的元素，如果没有这样的元素，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>lower(E e)</code>返回该集合中最大的元素严格小于给定的元素，如果没有这样的元素，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>pollFirst()</code>检索并删除第一个（最低）元素，如果此集合为空，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>E</code></td>
<td align="left"><code>pollLast()</code>检索并删除最后一个（最高）元素，如果此集合为空，则返回 <code>null</code> 。</td>
</tr>
<tr>
<td align="left"><code>Iterator&lt;E&gt;</code></td>
<td align="left"><code>iterator()</code>以升序返回此集合中的元素的迭代器。</td>
</tr>
<tr>
<td align="left"><code>Iterator&lt;E&gt;</code></td>
<td align="left"><code>descendingIterator()</code>以降序返回该集合中的元素的迭代器。</td>
</tr>
</tbody></table>
<h1 id="二元集合（映射）"><a href="#二元集合（映射）" class="headerlink" title="二元集合（映射）"></a>二元集合（映射）</h1><h2 id="Map"><a href="#Map" class="headerlink" title="Map"></a><code>Map</code></h2><table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>containsKey(Object key)</code>如果此映射包含指定键的映射，则返回 <code>true</code> 。</td>
</tr>
<tr>
<td align="left"><code>boolean</code></td>
<td align="left"><code>containsValue(Object value)</code>如果此地图将一个或多个键映射到指定的值，则返回 <code>true</code> 。</td>
</tr>
<tr>
<td align="left"><code>Set&lt;K&gt;</code></td>
<td align="left"><code>keySet()</code>返回此地图中包含的键的视图。</td>
</tr>
<tr>
<td align="left"><code>Collection&lt;V&gt;</code></td>
<td align="left"><code>values()</code>返回此地图中包含的值的视图。</td>
</tr>
<tr>
<td align="left"><code>Set&lt;Map.Entry&lt;K,V&gt;&gt;</code></td>
<td align="left"><code>entrySet()</code>返回此地图中包含的映射的视图。</td>
</tr>
<tr>
<td align="left"><code>V</code></td>
<td align="left"><code>get(Object key)</code>返回到指定键所映射的值，或 <code>null</code>如果此映射包含该键的映射。</td>
</tr>
<tr>
<td align="left"><code>default V</code></td>
<td align="left"><code>getOrDefault(Object key, V defaultValue)</code>返回到指定键所映射的值，或 <code>defaultValue</code>如果此映射包含该键的映射。</td>
</tr>
<tr>
<td align="left"><code>V</code></td>
<td align="left"><code>put(K key, V value)</code>将指定的值与该映射中的指定键相关联（可选操作）。</td>
</tr>
<tr>
<td align="left"><code>default V</code></td>
<td align="left"><code>putIfAbsent(K key, V value)</code>如果指定的键尚未与某个值相关联（或映射到 <code>null</code> ）将其与给定值相关联并返回 <code>null</code> ，否则返回当前值。</td>
</tr>
<tr>
<td align="left"><code>default V</code></td>
<td align="left"><code>replace(K key, V value)</code>只有当目标映射到某个值时，才能替换指定键的条目。</td>
</tr>
<tr>
<td align="left"><code>default boolean</code></td>
<td align="left"><code>replace(K key, V oldValue, V newValue)</code>仅当前映射到指定的值时，才能替换指定键的条目。</td>
</tr>
<tr>
<td align="left"><code>V</code></td>
<td align="left"><code>remove(Object key)</code>如果存在（从可选的操作），从该地图中删除一个键的映射。</td>
</tr>
<tr>
<td align="left"><code>default boolean</code></td>
<td align="left"><code>remove(Object key, Object value)</code>仅当指定的密钥当前映射到指定的值时删除该条目。</td>
</tr>
</tbody></table>
<p>需要注意 replace 和 putIfAbsent 的区别。</p>
<h2 id="Map-Entry"><a href="#Map-Entry" class="headerlink" title="Map.Entry"></a><code>Map.Entry</code></h2><p>它的角色类似于迭代器的角色，不过是二元的。</p>
<table>
<thead>
<tr>
<th align="left">Modifier and Type</th>
<th align="left">Method and Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>K</code></td>
<td align="left"><code>getKey()</code>返回与此条目相对应的键。</td>
</tr>
<tr>
<td align="left"><code>V</code></td>
<td align="left"><code>getValue()</code>返回与此条目相对应的值。</td>
</tr>
<tr>
<td align="left"><code>V</code></td>
<td align="left"><code>setValue(V value)</code>用指定的值替换与该条目相对应的值（可选操作）。</td>
</tr>
</tbody></table>
<blockquote>
<p>参考资料</p>
<p><a target="_blank" rel="noopener" href="https://docs.oracle.com/javase/8/docs/api/">Overview (Java Platform SE 8 </a></p>
</blockquote>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag"># 数据结构</a>
              <a href="/tags/Java%E9%9B%86%E5%90%88%E7%B1%BB/" rel="tag"># Java集合类</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/07/21/%E8%BF%99%E6%AC%A1%E5%BD%BB%E5%BA%95%E8%A7%A3%E5%86%B3%E5%9C%A8Hexo%E4%B8%AD%E6%B8%B2%E6%9F%93MathJax%E6%95%B0%E5%AD%A6%E5%85%AC%E5%BC%8F%E5%87%BA%E7%8E%B0%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%81%EF%BC%81%EF%BC%81/" rel="prev" title="这次彻底解决在Hexo中渲染MathJax数学公式出现的问题！！！">
                  <i class="fa fa-chevron-left"></i> 这次彻底解决在Hexo中渲染MathJax数学公式出现的问题！！！
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/07/24/List%E5%AE%9E%E7%8E%B0%E7%B1%BB%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%20%E2%80%94%E2%80%94%20LinkedList%E3%80%81ArrayList/" rel="next" title="List实现类源码分析 —— LinkedList、ArrayList">
                  List实现类源码分析 —— LinkedList、ArrayList <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">SongyangJi</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>





  





</body>
</html>
